package create.prototype;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Prototype implements Cloneable, Serializable {

	private static final long serialVersionUID = 1L;
	private String string;

	private SerializableObject obj = new SerializableObject();

	public SerializableObject getObject() {
		return obj;
	}

	public Object shallowClone() throws CloneNotSupportedException {
		return (Prototype) super.clone();
	}

	public Object deepClone() throws ClassNotFoundException, IOException {
		ByteArrayOutputStream bos = null;
		ObjectOutputStream oos = null;
		ByteArrayInputStream bis = null;
		ObjectInputStream ois = null;
		Object object = null;
		try {
			bos = new ByteArrayOutputStream();
			oos = new ObjectOutputStream(bos);
			oos.writeObject(this);

			bis = new ByteArrayInputStream(bos.toByteArray());
			ois = new ObjectInputStream(bis);
			object = ois.readObject();
		} finally {
			if (ois != null) {
				ois.close();
			}
			if (bis != null) {
				bis.close();
			}
			if (oos != null) {
				oos.close();
			}
			if (bos != null) {
				bos.close();
			}
		}
		return object;
	}
}

class SerializableObject implements Serializable {
	private static final long serialVersionUID = 1L;
}